Method: TimePieces::TimeSet#<<

Defined in:
lib/time_pieces/time_set.rb

#<<(new_td) ⇒ Object

Adds a new time duration. Removes invalid time durations.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/time_pieces/time_set.rb', line 8

def <<(new_td)
  if new_td.duration_seconds == 0
    
  else
    new_tds = []
    has_combined = false
    time_durations.each do |td|
      if new_td.overlaps?(td) || new_td.touches?(td)
        combined_td = td + new_td
        combined_td.time_durations.each do |td3|
          new_tds << td3
        end
        has_combined = true
      else
        new_tds << td
      end
    end
    new_tds << new_td unless has_combined
    self.time_durations = new_tds
  end
  return self
end